import 'package:flutter/material.dart' hide Feedback;
import 'package:sow_app_core/sow_app_core.dart';
import 'package:sow_app_i18n/sow_app_i18n.dart';

import '../../../../presenter/state_feedback_presenter.dart';
import '../info_page.dart';

class FeedbackPage extends StatefulWidget {
  const FeedbackPage({
    super.key,
    required this.presenter,
    required this.controller,
  });
  static const routeName = '${InfoPage.routeName}/feedback';

  final StateFeedbackPresenter presenter;
  final FeedbackController controller;

  @override
  State<FeedbackPage> createState() => _FeedbackPageState();
}

class _FeedbackPageState extends State<FeedbackPage> {
  @override
  void initState() {
    widget.presenter.presenterContext = context;
    widget.presenter.presenterSetState = setState;
    widget.controller.init();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(I18n.feedback_and_help),
      ),
      body: Stack(
        children: [
          Center(
              child: Icon(
            Icons.feedback,
            color: Colors.grey.shade300,
            size: 240,
          )),
          Column(
            children: [
              TextField(
                decoration: const InputDecoration(
                    prefixIcon: Icon(Icons.feedback), label: Text('填写反馈')),
                onSubmitted: (value) {
                  widget.controller.addFeedBack(value);
                },
              ),
              Expanded(
                  child: ListView(
                children: widget.presenter.feedbackList
                    .map((e) => ListTile(
                          title: Text(e.content),
                          subtitle: Text(e.createTime),
                        ))
                    .toList(),
              ))
            ],
          )
        ],
      ),
    );
  }
}
